package com.example.innospace.demos.web.controller;

import com.example.innospace.demos.pojo.Request.ProjectGeneralSetting;
import com.example.innospace.demos.pojo.enums.MessageEnum;
import com.example.innospace.demos.pojo.enums.ResponseCodeEnum;
import com.example.innospace.demos.pojo.result.R;
import com.example.innospace.demos.web.service.ProjectGeneralSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/project/generalSetting")
public class ProjectGeneralSettingController {

    @Autowired
    private ProjectGeneralSettingService projectGeneralSettingService;

    /**
     * 获取大体项目设定
     * @return
     */
    @GetMapping("/getGeneralSetting")
    public R<List<ProjectGeneralSetting>> getGeneralSetting() {
        List<ProjectGeneralSetting> settings=new ArrayList<>();
        settings = projectGeneralSettingService.getGeneralSetting();
        return R.success(ResponseCodeEnum.SUCCESS, settings, MessageEnum.OPERATION_SUCCESS);
    }

    /**
     * 保存大体项目设定
     * @param setting
     * @return
     */
    @PostMapping("/saveGeneralSetting")
    public R saveGeneralSetting(@RequestBody ProjectGeneralSetting setting) {
         projectGeneralSettingService.saveGeneralSetting(setting);
        return R.success(ResponseCodeEnum.SUCCESS, MessageEnum.OPERATION_SUCCESS);
    }

    /**
     *  更新大体项目设定
     * @param setting
     * @return
     */
    @PutMapping("/updateGeneralSetting")
    public R RupdateGeneralSetting(@RequestBody ProjectGeneralSetting setting) {
        try{
            projectGeneralSettingService.updateGeneralSetting(setting);
            return R.success(ResponseCodeEnum.SUCCESS, MessageEnum.OPERATION_SUCCESS);
        }catch (Exception e)
        {
            return R.error(ResponseCodeEnum.BAD_REQUEST,MessageEnum.OPERATION_FAILED);
        }


    }
}